﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using XmHttpServer;

namespace XmHttpServerForm
{
    public partial class SettingForm : Form
    {
        public SettingForm()
        {
            InitializeComponent();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
             

            Tools.configSetValue("IsAutoRun", chkAutoStart.Checked.ToString().ToLower());

            Tools.configSetValue("IsRunOnWindowsStart", chkAutoWindowsStart.Checked.ToString().ToLower());
            if (chkAutoWindowsStart.Checked)
            {
                Tools.RunWhenStart(true, Application.ProductName, Application.StartupPath + "\\" + Application.ProductName + ".exe");
            }
            else
            {
                Tools.RunWhenStart(false, Application.ProductName, Application.StartupPath + "\\" + Application.ProductName + ".exe");
            }
            //rest配置
            Tools.configSetValue("RequireAuthentication", chkRestSafe.Checked.ToString().ToLower());
            Tools.configSetValue("IsLogToTextBox", chkLogToTextBox.Checked.ToString().ToLower());
            Tools.configSetValue("IsLogToFile", chkLogToFile.Checked.ToString().ToLower());
            //设置是否启用rest安全性
            MainForm.mainForm.setRequireAuthentication(chkRestSafe.Checked);
            //设置日志是否记录到文件
            MainForm.mainForm.setIsLogToFile(chkLogToFile.Checked);
            //设置日志是否记录到日志记录框
            MainForm.mainForm.setIsLogToTextBox(chkLogToTextBox.Checked);
            
            this.Close();
            this.Dispose();
        }
       

        private void frmSetting_Load(object sender, EventArgs e)
        {
            chkAutoStart.Checked = "true".Equals(Tools.configGetValue("IsAutoRun")) ? true : false;
            chkAutoWindowsStart.Checked = "true".Equals(Tools.configGetValue("IsRunOnWindowsStart")) ? true : false;
            
            //rest配置
            chkRestSafe.Checked = "true".Equals(Tools.configGetValue("RequireAuthentication")) ? true : false;
            chkLogToTextBox.Checked = "true".Equals(Tools.configGetValue("IsLogToTextBox")) ? true : false;
            chkLogToFile.Checked = "true".Equals(Tools.configGetValue("IsLogToFile")) ? true : false;
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void chkAutoWindowsStart_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAutoWindowsStart.Checked)
            {
                chkAutoStart.Checked = true;
            }
        }




    }
}
